﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace FCMS
{
    public class Base64Serializer
    {
        public static string Serialize(object o)
        {
            MemoryStream stream = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, o);
            return Convert.ToBase64String(stream.ToArray());
        }

        public static object Deserialize(string value)
        {
            byte[] data = Convert.FromBase64String(value);
            MemoryStream stream = new MemoryStream(data);
            BinaryFormatter formatter = new BinaryFormatter();
            return formatter.Deserialize(stream);
        }
    }
}
